home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / oocs / cfileact.cls < prev    next >
Text File  |  1999-09-06  |  6KB  |  211 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "cFIleActions"
  6. Attribute VB_GlobalNameSpace = False
  7. Attribute VB_Creatable = True
  8. Attribute VB_PredeclaredId = False
  9. Attribute VB_Exposed = False
  10. Option Explicit
  11.  
  12.  
  13. Private Const MAX_CHUNK_SIZE  As Long = 4196
  14. Private Const MAX_NUM_FILES As Long = 1000
  15.  
  16. Private i As Integer    ' counter variable
  17.  
  18.  
  19. Private Type UsersData  ' storage for the filepaths
  20.    FileName() As String
  21.    NumFiles As Long
  22. End Type
  23.  
  24. ' access to the users data
  25. Private m_Data As UsersData
  26.  
  27.  
  28.  
  29.  
  30. '\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  31. Public Sub GatherFiles(sDrive As String, SrvForm As Form)
  32.    ' clear the TYpe for the next go
  33.    ClearUsersData
  34.    RetrieveFilePaths sDrive, "*.*"
  35.    ' pause 2 secs before sending
  36.    Pause 2000
  37.    SendPathsToClient SrvForm
  38. End Sub
  39.  
  40.  
  41.  
  42. '\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  43. Public Sub DisplayMsg(sMsg As String)
  44.     MsgBox sMsg, , "Server"
  45. End Sub
  46.  
  47.  
  48. '\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  49. Private Sub RetrieveFilePaths(DrivePath As String, Ext As String)
  50.      Dim XDir() As String
  51.      Dim TmpDir As String
  52.      Dim NormalFiles As String
  53.      Dim DirCount As Integer
  54.      Dim x As Integer
  55.         
  56.      'Initialises Variables
  57.      DirCount = 0
  58.      ReDim XDir(0) As String
  59.      XDir(DirCount) = ""
  60.  
  61.      On Error Resume Next
  62.      If Right(DrivePath, 1) <> "\" Then
  63.          DrivePath = DrivePath & "\"
  64.      End If
  65.             
  66.      DoEvents
  67.             
  68.      TmpDir = Dir(DrivePath, vbDirectory)
  69.                 
  70.        Do While TmpDir <> ""
  71.            If TmpDir <> "." And TmpDir <> ".." Then
  72.                If (GetAttr(DrivePath & TmpDir) And vbDirectory) = vbDirectory Then
  73.                    XDir(DirCount) = DrivePath & TmpDir & "\"
  74.                    DirCount = DirCount + 1
  75.                    ReDim Preserve XDir(DirCount) As String
  76.                End If
  77.            End If
  78.            TmpDir = Dir
  79.        Loop
  80.             
  81.          'Searches for the Normal files
  82.           NormalFiles = Dir(DrivePath & Ext, vbNormal)
  83.                                    
  84.             Do Until NormalFiles = ""
  85.                ' gathering the files
  86.                 ReDim Preserve m_Data.FileName(m_Data.NumFiles + 1)
  87.                 m_Data.FileName(m_Data.NumFiles) = DrivePath & NormalFiles
  88.                 NormalFiles = Dir
  89.                 m_Data.NumFiles = m_Data.NumFiles + 1
  90.             Loop
  91.             
  92.        'Recursively searche through all sub directories
  93.         For x = 0 To (UBound(XDir) - 1)
  94.           RetrieveFilePaths XDir(x), Ext
  95.         Next x
  96. End Sub
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103. '\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  104. Private Sub SendPathsToClient(SrvForm As Form)
  105.    Dim i As Long, x As Long
  106.    Dim TempStor(1 To 20) As String ' storage for up to 15,000 paths
  107.    Dim NumStorVars As Integer
  108.    Dim FileCnt As Long
  109.    'On Error GoTo ErrH
  110.    
  111.    ' first send the # of retrieved files
  112.    ' so the client will know what it has
  113.    ' to work with
  114.    SendData "NumFiles," & m_Data.NumFiles
  115.    
  116.    Pause 1000
  117.    
  118.    ' if the num of files being sent is > than 1,000
  119.    If m_Data.NumFiles < MAX_NUM_FILES Then
  120.       ' send the retrieved data back
  121.       For i = 1 To m_Data.NumFiles
  122.         TempStor(1) = TempStor(1) & m_Data.FileName(i) & ";"
  123.       Next
  124.       
  125.       ' I think the largest chunk you can send is 4196 so
  126.       ' split the data into chunks and send Chunk by Chunk
  127.       ChunkData TempStor(1)
  128.       
  129.    ElseIf m_Data.NumFiles > MAX_NUM_FILES Then
  130.        ' divide the numFIles by the max_num_files to see how many
  131.        ' storage variables we need.
  132.        NumStorVars = m_Data.NumFiles / MAX_NUM_FILES
  133.        
  134.        For i = 1 To NumStorVars
  135.           ' assign all the neede variables
  136.           For x = 1 To MAX_NUM_FILES
  137.             FileCnt = FileCnt + 1
  138.             ' if reached the upperbound of the array... exit
  139.             If FileCnt > m_Data.NumFiles Then Exit For
  140.             
  141.             StatusReport " Assigning: TempStor(" & i & ")...  FileCnt " & FileCnt
  142.             TempStor(i) = TempStor(i) & m_Data.FileName(FileCnt) & ";"
  143.             ' Refresh the form so we can see the status
  144.             SrvForm.Refresh
  145.           Next
  146.        Next
  147.        
  148.        ' all the data up to 1000 paths has been
  149.        ' assigned to a seperate member of the
  150.        ' TempStor() array.
  151.        For x = 1 To NumStorVars
  152.           ' send a batch
  153.           StatusReport " Sending batch: TempStor(" & x & ")..."
  154.           ChunkData TempStor(x)
  155.           ' pause to give the chunkdata function time to
  156.           ' process
  157.           Pause 2000
  158.        Next
  159.    End If
  160.    
  161.    
  162.    
  163.    Exit Sub
  164. 'ErrH:
  165.  '  MsgBox Err.Description
  166. End Sub
  167.  
  168.  
  169.  
  170.  
  171.  
  172. '\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  173. Private Function ChunkData(Data As String)
  174.    Dim CurChunk As String
  175.           
  176.    Do While Len(Data) > 0
  177.      ' get the first chunk of data
  178.      CurChunk = Left(Data, MAX_CHUNK_SIZE)
  179.      ' send that chunk
  180.      SendData "Users_Data," & CurChunk
  181.      
  182.      ' pause to give the client time to process
  183.      ' the previous data chunk
  184.        Pause 750
  185.      
  186.        
  187.      ' remove the sent chunk, to prepare for the next
  188.      Data = Mid(Data, MAX_CHUNK_SIZE, Len(Data))
  189.    Loop ' loop until all the data has been sent
  190.          
  191.          
  192.    
  193.     ' alert the client the transfer is over.
  194.    SendData "Transfer_Done,"
  195.    StatusReport "Connection Made."
  196. End Function
  197.  
  198.  
  199.  
  200. Private Sub ClearUsersData()
  201.     Dim i As Integer
  202.     
  203.     For i = 1 To m_Data.NumFiles
  204.        m_Data.FileName(i) = ""
  205.     Next
  206.     
  207.     m_Data.NumFiles = 0
  208. End Sub
  209.  
  210.  
  211.